<template>
  <div class="reply-cc">
    <!-- 评论回复 -->
    <van-nav-bar
      class="header"
      :title="
        comment.reply_count > 0 ? `${comment.reply_count}条回复` : '暂无回复'
      "
    >
      <van-icon slot="right" name="cross" @click="$emit('close')" />
    </van-nav-bar>
    <div class="str">
      <!-- 当前评论项 -->
      <comment-item :comment="comment" />
      <!-- 评论的回复列表 -->
      <van-cell title="全部回复" />
      <article-comment :list="CommentList" :source="comment.com_id" type="c" />
    </div>

    <!--发布评论  -->

    <div class="footer">
      <van-button
        size="small"
        class="ff-btn"
        round
        @click="isCommentShow = true"
      >
        回复
      </van-button>
    </div>
    <!-- 评论弹层 -->
    <van-popup v-model="isCommentShow" position="bottom">
      <comment-list :target="comment.com_id" @post-success="onPostSuccess" />
    </van-popup>
  </div>
</template>

<script>
import ArticleComment from "./article-comment.vue"; //评论列表
import CommentItem from "./comment-item.vue";
import CommentList from "./commentlist.vue";
export default {
  name: "Reply",
  props: {
    comment: {
      type: Object,
      required: true,
    },
  },
  components: {
    ArticleComment,
    CommentItem,
    CommentList,
  },
  data() {
    return {
      isCommentShow: false,
      CommentList: [], // 评论回复列表
    };
  },
  methods: {
    onPostSuccess(data) {
      console.log(data);
      // 更新回复数据  关闭弹层  内容置顶
      this.comment.reply_count++;
      this.isCommentShow = false;
      this.CommentList.unshift(data.new_obj);
    },
  },
};
</script>

<style scoped lang="less">
.str {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 96px;
  overflow-y: auto;
}
.reply-cc {
  padding: 96px;
  .footer {
    height: 96px;
    width: 100%;
    left: 0;
    right: 0;
    position: fixed;
    background-color: #fff;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid #d8d8d8;
    .ff-btn {
      width: 60%;
    }
  }
  .header {
    top: 0;
  }
}
</style>